#ifndef _COMMON_DEFINE_H_
#define _COMMON_DEFINE_H_

//#include <iostream>
#include <vector>
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif
#endif /* End of #ifdef __cplusplus */

#include <stdio.h>
#include <stdint.h>
#include <sys/types.h>
#include <stdarg.h>
#include <string.h>

//编译时使用
// -D__NOTDIR_FILE__='\"$(subst $(dir $<),,$<)\"'


#define LOG_PRT(level, format, ...) \
{\
    do {\
            char log_buffer[2048] = {};\
            snprintf(log_buffer,sizeof(log_buffer) - 1,\
                                    "%s[%s:%d]%s:" format, level, __NOTDIR_FILE__,__LINE__,__FUNCTION__, ##__VA_ARGS__);\
			printf("%s",log_buffer);\
    }while(0);\
}

#define DEBUG_PRT(format, ...)      LOG_PRT("DEBUG", format, ##__VA_ARGS__)
#define INFO_PRT(format, ...)       LOG_PRT("INFO", format, ##__VA_ARGS__)
#define ERRO_PRT(format, ...)       LOG_PRT("ERROR", format, ##__VA_ARGS__)



#define SYS_VERSION             "Version.1.1.4"

#define VIS_MIPI_VI_PIPE        0
#define VIS_MIPI_VI_CHN         0
#define VIS_VPSS_GRP_ID         0
#define VIS_VPSS_ALGOR_CHN      2
#define VIS_VPSS_RTSP_CHN       3
#define VIS_VENC_ID             0


#define VIS_FRAME_RATE          30

#define CHN_NUM_MAX             4
#define VPSS_CHN_NUM_MAX        4 


// rtsp 为绘制图像处理结果最大缓存帧
#define MAX_FRAME_WAIT_IMAGE_PROCESS   3


#define SERIAL_SERVER_COM       "/dev/ttyAMA1"
#define SERIAL_SERVER_COM_SPEED 230400   

#define CANBUS_DEVICE_CANID     0x12
#define CANBUS_DEVICE_NAME      "can0"


#define VPSS_CHN2_IMAGE_WIDTH       1280
#define VPSS_CHN2_IMAGE_HEIGHT     1024

#define VI_INPUT_WIDTH          3840
#define VI_INPUT_HEIGHT         2160

#define VCAP_VO_DEV_UHD    0
#define VCAP_VO_CHN_ID     0


#define VCAP_VO_DEV_CVBS    1
#define VCAP_VO_CHN_CVBS    0

#define RGN_CROSSHAIR_ID   0
#define RGN_CROSSHAIR_FILE_PATH "./resource/22.bmp"


//协议接收结构体
typedef struct __attribute__((packed, aligned(1))) ssControlInfo{
    uint16_t    fixHead;
    uint16_t    frame_id;
    uint8_t     frameLength;        //帧长
    uint8_t     launchFlag;         //发射标志
    uint8_t     targetType;         //目标类型
    uint8_t     targetLock;         //目标锁定
    uint8_t     targetModify;       //目标切换
    uint8_t     detectMode;         //检测模式
    uint16_t    autoPitchlos;       //自动检测目标俯仰视线
    uint16_t    autoYawlos;         //自动检测目标偏航视线
    uint16_t    manualPitchlos;     //手动检测目标俯仰视线
    uint16_t    manualYawlos;       //手动检测目标偏航视线
    uint8_t     targetWidth;        //手动检测目标长度
    uint8_t     targetHeight;       //手动检测目标高度
    uint8_t     detectThreshold;    //检测阈值
    uint8_t     exposureMode;       //曝光控制
    uint8_t     resver_1;           // 保留
    short       pitchSightAngle;    //俯仰视线角
    short       yawLineSightAngle;  //偏航视线角
    uint8_t     pointSwitch;        //指向开关
    uint8_t     lossView;           //出视场 

    uint8_t     reverse_2[8];       //保留参数
    uint8_t     checkSum;           //校验和
    uint16_t    fixTail;
    // 2*9 = 18 + 8 + 13 = 39
}ControlInfo;

//协议发送结构体
typedef struct __attribute__((packed, aligned(1))) ssBoradStatus{

    uint16_t    fixFrameHead;               //帧头
    uint8_t     frameLength;                //帧长
    uint16_t    frameID;                    //帧id
    uint8_t     selfTestStat;               //自检状态
    uint8_t     sysStat;                    //系统状态
    uint8_t     xIndex;                     //x编号
    short       pitchSightAngle;            //俯仰视线角
    short       yawLineSightAngle;          //偏航视线角
    uint8_t     launchFlag;                 //发射标志
    uint8_t     targetType;                 //目标类型
    uint8_t     targetLock;                 //目标锁定
    uint8_t     targetModify;               //目标切换
    uint8_t     detectMode;                 //检测模式
    uint16_t    Pitchlos;                   //俯仰视线  0-3200pix 左上角为原点
    uint16_t    Yawlos;                     //偏航视线  0-2200pix
    uint8_t     targetWidth;                //目标长度  0-255pix
    uint8_t     targetHeight;               //目标高度  0-255pix
    uint8_t     directionSwitch;            //接收指向开关
    short       sendpitchSightAngle;        //下发俯仰视线角
    short       sendyawLineSightAngle;      //下发偏航视线角
    uint8_t     outofView;                 //出视场
    uint8_t     reverse[8];                 //保留
    uint8_t     telemetryData[48];          //遥测数据
    uint8_t     checksum;                   //校验和
    uint16_t    fixFrameTail;               //帧尾

    ssBoradStatus(){
        memset(this,0xFF,sizeof(ssBoradStatus));
        fixFrameHead = 0x55AA;
        frameLength = 0x52;

        memset(reverse,0xFF,8);
        memset(telemetryData,0,48);

        fixFrameTail = 0xAA55;
    }

}BoradStatus;


class InfoIdentify
{
public:
    InfoIdentify(){}
    InfoIdentify(int px,int py,int pw,int ph):x(px),y(py),w(pw),h(ph){
        classId = 0;
    }

    int classId;
    int x, y, w, h;
};

class image_detect_info
{
public:
    std::vector<InfoIdentify> detect;
    uint64_t pts;
};

#ifdef __cplusplus
#if __cplusplus
}
#endif
#endif


#endif